<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 class RelatedPost{
     public $multiplePostId;
     public $multipleTags;
     public $resultList;

     public function RelatedPost($inputID,$multipleTags) {
         $this->multiplePostId=$inputID;
         $this->multipleTags=$multipleTags;
         $this->resultList=array();
    }
    public function execute(){
        $queryBuild= array();
        
        /* collect category and tags */
        if(count($this->multiplePostId)>0)
            $queryBuild['category']="";
        for($i=count($this->multiplePostId)-1; $i>=0; --$i)
        {
            $queryBuild['category'] .= $this->multiplePostId[$i]->term_id . ",";
        }

        /*
        if(count($this->multipleTags)>0)
            $queryBuild['tag']="";
        for($i=count($this->multipleTags)-1; $i>=0; --$i)
        {
            $queryBuild['tag'] .= $this->multipleTags[$i]->slug . ",";
        }                
        */
        
        global $post;
        $backupPost= $post;
		$args = array( 'numberposts' => 10, 'category' => $queryBuild['category'], 'order'=>'DESC');
		$myposts = get_posts( $args );
		$i=0;
		foreach( $myposts as $post ) :	setup_postdata($post);
			$this->resultList[$i]['href']=get_permalink();
			$this->resultList[$i]['title']=get_the_title();
			++$i;
		endforeach;
		$post=$backupPost;
    }
}

?>